<?php

namespace app\index\controller;

use app\blog\model\MessageModel;
use app\blog\model\LabelModel;
use app\blog\model\ArticleModel;
use app\blog\model\LinkModel;
use think\App;
use think\Db;
use think\Request;


class Index extends BaseController
{
    public function __construct(Request $request, App $app)
    {
        parent::__construct($request, $app);
    }

    public function index()
    {
        $data = ArticleModel::get_article();
        $page = $data->render();
        $this->assign('lst', $data);
        $this->assign('page', $page);
        return $this->fetch();
    }

    public function label()
    {
        $lst = LabelModel::lst_labels();
        $this->assign('label', $lst);
        return view();
    }

    public function about()
    {
        return view();
    }

    public function message()
    {
        return view();
    }

    public function message_add()
    {
        if (request()->isPost()) {
            $message = $_POST['message'];
            $conn = new MessageModel;
            $data = array(
                'message' => $message,
                'add_time' => date('Y-m-d H:i:s'),
            );
            $conn->save($data);
            return json(['code' => 200, 'msg' => '留言成功']);
        }
    }

    public function link()
    {
        $link = LinkModel::where('show', '=', 1)->select();
        $this->assign('link', $link);
        return view();
    }
}
